package com.xuecheng.content.controller;

import com.xuecheng.api.content.CourseTeacherApi;
import com.xuecheng.api.content.model.dto.CourseTeacherDTO;
import com.xuecheng.api.content.model.vo.CourseTeacherVO;
import com.xuecheng.content.common.util.UAASecurityUtil;
import com.xuecheng.content.convert.CourseTeacherConvert;
import com.xuecheng.content.service.CourseTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 课程-教师关系表 前端控制器
 * </p>
 *
 * @author itcast
 */
@Slf4j
@RestController
public class CourseTeacherController implements CourseTeacherApi {

    @Autowired
    private CourseTeacherService courseTeacherService;

    @GetMapping("courseTeacher/list/{courseBaseId}")
    public List<CourseTeacherDTO> queryCourseTeacherList(@PathVariable Long courseBaseId) {

        Long companyId = UAASecurityUtil.getCompanyId();


        return courseTeacherService.queryCourseTeacherList(courseBaseId, companyId);
    }


    @PostMapping("courseTeacher")
    public CourseTeacherDTO createOrModifyCourseTeacher(@RequestBody CourseTeacherVO courseTeacherVO) {

        Long companyId = UAASecurityUtil.getCompanyId();

        CourseTeacherDTO courseTeacherDTO = CourseTeacherConvert.INSTANCE.courseTeacherVoToDTO(courseTeacherVO);

        return courseTeacherService.createOrModifyCourseTeacher(courseTeacherDTO, companyId);
    }

    @DeleteMapping("courseTeacher/course/{courseBaseId}/{courseTeacherId}")
    public boolean removeCourseTeacher(@PathVariable Long courseBaseId,
                                       @PathVariable Long courseTeacherId) {

        return courseTeacherService.removeCourseTeacher(courseBaseId, courseTeacherId);
    }
}
